---
category: Array
created: '2020-05-20'
title: Sort an array of numbers
updated: '2021-10-13'
---

**JavaScript version**

```js sort.js
const sort = (arr) => arr.sort((a, b) => a - b);
```

**TypeScript version**

```ts sort.ts
const sort = (arr: number[]): number[] => arr.sort((a, b) => a - b);
```

**Example**

```js example.js
sort([1, 5, 2, 4, 3]); // [1, 2, 3, 4, 5]
```
